package cn.tedu.rabbitmqboot.m2;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Scanner;

@Component
public class Producer {
    @Autowired
    private AmqpTemplate amqpTemplate;
    //send方法需要手动调用,发送消息
    public void send(){//自定义的方法
        while (true){
            System.out.println("输入:");
            String msg = new Scanner(System.in).nextLine();
            //Spring封装整合之后,默认是持久消息
            //如果要发送非持久消息,需要添加第三个参数,MessagePostProcessor
            amqpTemplate.convertAndSend("task_queue",msg);
        }
    }

}
